<?
	include_once 'functionsCompanies.php';
	include 'headermenu.php';


?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
 "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
   <link rel="stylesheet" href="yui.css" type="text/css">
<head>
	<title>Methodology Portal</title>
</head>
<body>
<div id="doc" class="yui-t7">
   
   <div id="bd" role="main">
   
   <div class="yui-gc">
    <div class="yui-u first">
	<!-- YOUR DATA GOES HERE -->
    <form action="" name="testQR" method="post" >
	<div align="right">  <input type="submit" name="add" value="Adauga" align="right"> </div>
	</form>
	    </div>
    <div class="yui-u">
	<!-- YOUR DATA GOES HERE -->
	    </div>
 </div>
   
	<div class="yui-gc">
    <div class="yui-u first">
	<!-- YOUR DATA GOES HERE -->


	<?
	$dbh=dbConn();
	//####FUNCTII:
	//####se pare ca daca pun functiile inainte se da refresh la pagina singura!!! si cred ca stiu de ce!
	//####STERGE PROIECT:
	if(isset($_POST['qr_del']))
	{
		//echo ("Proiectul identificat cu numarul ".$_GET[rowid]." a fost sters.");
		mysql_query("delete from companies where id = ".$_GET[rowid].";") or die(mysql_error());
			unset($_GET[rowid]);
		//refreshPage('http://localhost/methodology/');
	}

	//####ADAUGA PROIECT:
	if(isset($_POST['qr_add']))
	{
		if($_POST['cname'] != null) {
			//echo ("A fost adaugat un nou proiect.");
			
		
			
			mysql_query("INSERT INTO companies (id, name, cui, j, street, nr, building, floor, city, county, country, postal_code, bank, bank_account) VALUES (NULL,'".$_POST['cname']."', '".$_POST['cui']."', '".$_POST['j']."', '".$_POST['street']."', '".$_POST['nr']."', '".$_POST['building']."', '".$_POST['floor']."', '".$_POST['city']."', '".$_POST['county']."', '".$_POST['country']."', '".$_POST['postalcode']."', '".$_POST['bank']."', '".$_POST['bank_account']."');") or die(mysql_error());  
				unset($_GET[rowid]);
			//refreshPage('http://localhost/methodology/');
		}
	}

	//####MODIFICA PROIECT:
	if(isset($_POST['qr_update']))
	{
		//echo ("Proiectul identificat cu numarul ".$_GET[rowid]." a fost modificat.");
		$sql = "UPDATE `ec_methodology`.`companies` SET `name` = '".$_POST['cname']."', `cui` = '".$_POST['cui']."', `j` = '".$_POST['j']."', `street` = '".$_POST['street']."', `nr` = '".$_POST['nr']."', `building` = '".$_POST['building']."', `floor` = '".$_POST['floor']."', `city` = '".$_POST['city']."', `county` = '".$_POST['county']."', `country` = '".$_POST['country']."', `postal_code` = '".$_POST['postalcode']."', `bank` ='".$_POST['bank']."', `bank_account` = '".$_POST['bank_account']."' WHERE `companies`.`id` = ".$_GET[rowid].";";
		
		mysql_query($sql) or die(mysql_error());  
			unset($_GET[rowid]);
		//refreshPage('http://localhost/methodology/');
	}




	$result = returnQuery("Select * from companies;",$dbh);
	
	//####afisam inregistrarile in tabela:
	while ($row = mysql_fetch_assoc($result)) 
	{
		
		/////////
		
		echo "<table width='500' border='1'>";
		
 echo "<tr><td colspan='2' bgcolor=#00AFF2>Nume:  <a href='companies.php?rowid=".$row["id"]."'>".$row["name"]." </a> </td></tr>";
  echo "<tr><td width='250'>Cui: ".$row["cui"]."</td><td width='250'>J: ".$row["j"]."</td></tr>";
 echo "<tr><td colspan='2'>Adresa: ".$row["street"]." ".$row["nr"]." ".$row["building"]." ".$row["floor"]." ".$row["city"]." ".$row["county"]." ".$row["country"]." ".$row["postal_code"]."</td></tr>";
 echo "<tr><td width='250'>Banca: ".$row["bank"]."</td><td width='250'>Cont: ".$row["bank_account"]."</td></tr>";
  
         echo "</table>";
		 echo "<br>";
		
		///////////	
	}

	mysql_free_result($result);	
	?>
 

 
     </div>
    <div class="yui-u">
 <!-- AL DOILEA ECRAN!!! -->
 	<?

	
	
		//####afisam sectiunea add/update/delete:
	if(isset($_POST['add'])) 
	{
		unset($_GET[rowid]);
		display($_GET[0]);
	}
	
	//####Functie pentru selectarea unui proiect:
	if (isset($_GET[rowid])!=0)
	{
		
		display($_GET[rowid]);
	}
	
	//####Functie pt butonul Anulare:
	if(isset($_POST['qr_cancel'])) 
	{
			unset($_GET[rowid]);
		refreshPage('http://localhost/methodology/companies.php');
	}
	
	//####Inchidem sesiunea DB:
	dbClose($dbh);
	?>

 <br>
 
     </div>
</div>
 

	</div>
   
</div>
</body>
</html>
<? include 'footer.php'; ?>